package com.innodealing.config;

import com.innodealing.constants.AppConstants;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Flink环境配置类
 * 
 * @author 系统生成
 * @date 2024/12/18
 */
public final class FlinkConfig {
    
    private FlinkConfig() {
        // 私有构造函数，防止实例化
    }
    
    /**
     * 配置Flink流式执行环境
     * 
     * @param params 参数工具
     * @return 配置好的流式执行环境
     */
    public static StreamExecutionEnvironment createStreamExecutionEnvironment(ParameterTool params) {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        
        // 启用检查点
        env.enableCheckpointing(AppConstants.Job.DEFAULT_CHECKPOINT_INTERVAL);
        
        // 设置并行度
        final int parallelism = params.getInt(
            AppConstants.ParameterKeys.PARALLELISM,
            AppConstants.Job.DEFAULT_PARALLELISM
        );
        env.setParallelism(parallelism);
        
        return env;
    }
    
    /**
     * 获取Kafka Bootstrap Servers配置
     * 
     * @param params 参数工具
     * @return Kafka Bootstrap Servers
     */
    public static String getKafkaBootstrapServers(ParameterTool params) {
        return params.get(AppConstants.ParameterKeys.KAFKA_BOOTSTRAP_SERVERS,"10.64.10.65:9092");
    }
} 